import { Component, Injector, ViewEncapsulation, ViewChild, AfterViewInit } from '@angular/core';
import { Http } from '@angular/http';
import { AppComponentBase } from '@shared/common/app-component-base';
import { appModuleAnimation } from '@shared/animations/routerTransition';
import { Table } from 'primeng/components/table/table';
import { Paginator } from 'primeng/components/paginator/paginator';
import { WorkshopDomainServiceProxy, ValidationDomainDto, ValidationInfoDto } from '@shared/service-proxies/service-proxies';

@Component({
  templateUrl: './val-domain.component.html',
  styleUrls: ['./val-domain.component.less'],
  encapsulation: ViewEncapsulation.None,
  animations: [appModuleAnimation()]
})

export class ValDomainComponent extends AppComponentBase implements AfterViewInit {

  @ViewChild('dataTable') dataTable: Table;
  @ViewChild('paginator') paginator: Paginator;

  anyncing = false;

  domains = Array<ValidationDomainDto>();

  currentFlow = Array<ValidationInfoDto>();

  constructor(
    injector: Injector,
    private _workshopDomainServiceProxy: WorkshopDomainServiceProxy,
  ) {
    super(injector);
  }

  ngAfterViewInit(): void {
    this.getComponentsConfigs();
  }

  getComponentsConfigs() {
    this.primengTableHelper.showLoadingIndicator();

    this._workshopDomainServiceProxy.getAllValidationDomains()
      .subscribe(result => {
        this.domains = result;
        this.primengTableHelper.hideLoadingIndicator();
      });

  }

  getKeys(item) {
    let items = this.domains.filter((el) => {
      return el === item;
    });

    if (items.length >= 0) {
      return items[0].validationInfoDtos;
    }
    return null;
  }


}
